package org.cupk2.base.jwt;

import io.jsonwebtoken.Claims;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 封裝claims
 */
public class CupkJwtClaims {
    private Map<String, Object> claims = new HashMap<>();
    private Date expiration;

    public static CupkJwtClaims getInstance() {
        return new CupkJwtClaims();
    }

    public CupkJwtClaims(Claims claims) {
        this.claims.putAll(claims);
        this.expiration = claims.getExpiration();
    }

    private CupkJwtClaims() {

    }

    public CupkJwtClaims addFeild(CupkJwtConfig.ClaimsKey claimsKey, Object value) {
        claims.put(claimsKey.getKey(), value);
        return this;
    }

    public Map<String, Object> getClaims() {
        return claims;
    }

    public CupkJwtClaims addUserKey(String userKey) {
        claims.put(CupkJwtConfig.ClaimsKey.LoginName.getKey(), userKey);
        return this;
    }

    public Date getExpiration() {
        return expiration;
    }

    public Object get(CupkJwtConfig.ClaimsKey claimsKey) {
        return claims.get(claimsKey.getKey());
    }
}
